const express = require('express');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleWare = require("webpack-hot-middleware");

const app = express();
const config = require('./webpack.dev.js');
const compiler = webpack(config);

// Tell express to use the webpack-dev-middleware and use the webpack.config.js
// configuration file as a base.
app.use(webpackDevMiddleware(compiler, {
  publicPath: config.output.publicPath
}));

//将编译器挂载给 webpack dev middleware
app.use(webpackHotMiddleWare(compiler, {
	heartbeat: 2000
}));

// Serve the files on port 7777.
app.listen(7777, function () {
	let keys = Object.keys(config.entry);
	let str = '页面地址\n'
	for (let i = 0; i < keys.length; i++) {
  	str = str + 'localhost:7777/' + keys[i] + '.html\n';
	};
	console.log(str);
});